JAVAScript-EAI

BlaxxunContact(3.07以上版本)为JavaScript和VBScript提供一种应用起来非常简单的外部脚本接口,它允许你从已经命名的节点当中读写任意一个域值。以字符串形式输入的值被自动的转换成适当的类型。并且,VBScript(in Internet Explorer)与 JavaScript(in Netscape)的方法能够被VRML Script内部的Script节点调用。

浏览器句柄(

JS调用支持
以下是可用于通过JavaScript访问的blaxxun3D接口
setNodeEventIn
(String nodeName,
String eventInName,
String value) 设置已命名的节点的指定事件入口值,其value会自动转换成该事件入口的类型
getNodeEventOut
(String nodeName,
String eventOutName) 返回一个事件出口的值,并把该值转换成字符串格式
OnNextViewpoint( )
(仅用于IE浏览器!) 激活视点堆栈当中的下一个视点
setNextViewpoint( )
(仅用于Netscape浏览器!) 与上面的函数功能相同,但是只能用于Netscape浏览器

在VRML当中访问
可以在VRML文件当中访问HTML当中任何一个JavaScript函数。把下面的这个调用方法应用于Anchor节点,或者用Script节点当中的Browser . loadURL方法来指定相应的函数方法。

“javascript:myJSFunction();”

如果指定的方法是定义在一个HTML文档的其他框架当中,则目标必须用Anchor节点的parameters域或者在Browser . loadURL方法的第二个参数。请参考以下例子:

Example 1: Calling a JS-Function by an Anchor
DEF anchor1 Anchor{  JavaScript
url”javascript:externalFunction();”
parameter[“target=_self”]  
children[ #some geometry   ]
}
Example 2: Calling a JS-Function from a Script
Script{  
field MFString param [“target=someFrame”, “”]  
eventIn SFTime touch  
url”vrmlscript:  
function touch()  
{
       Browser.loadURL(‘javascript:externalFunction()’, param);  
}  

}

为了能够影响3D场景,你需要获得一个VRML浏览器的句柄。可以利用定义在embed标签当中的名称来访问插件,各自的ID定义在Objedt标签内。这些参量的详细资料请参考”Embedding blaxxunContact”

blaxxun Contact 3D (release 3.07 or higher) supports an easy-to-use external scripting interface for Javascript and VBScript. It allows to read and write any fields values of named nodes. String input values are converted automatically to the appropriate field types. Additionally VBScript (in Internet Explorer) and Javascript (in Netscape) methods can be called from internal VRMLScript script nodes.

General syntax

void Browser.setNodeEventIn( String nodeName, String eventInName, String value)

set the value for the specified eventIn converting value to the type of the eventIn
String Browser.getNodeEventOut( String nodeName, String eventOutName)
returns the value of the eventOut converted to a string
callback from internal script nodes:
Netscape Javascript: OnEvent ( String, par1, String par2, String timestamp )
Internet Explorer VBscript: <Contact3D_ID>_OnEvent ( String, par1, String par2, String timestamp )
the method OnEvent can be called from VRMLScript using the Browser.loadURL() method with 2 parameters (see example)
HTML Page contents for using the Script EAI with Microsoft and Netscape Browsers

1. Embed the VRML browser and give it a name:

<OBJECT CLASSID=”CLSID:4B6E3013-6E45-11D0-9309-0020AFE05CC8″ ID= CC3D WIDTH=100% HEIGHT=50%>

<PARAM NAME=”SRC” VALUE=”sample.wrl”>

<EMBED name= CC3D SRC=”sample.wrl” TYPE= “application/x-cc3d” WIDTH=100% HEIGHT=50%>

</OBJECT>

2. Sending an event to VRML from JavaScript:

You can send events to VRML from JavaScript using setNodeEventIn, as
shown below.    It requires, as parameters, the VRML target node, the field
that will be changed, and the value that will be sent.    The parameters can
be set as strings, and will be automatically converted to the correct
type.

function sendEvent(node, field, value)
{
document.Contact 3D.setNodeEventIn(node, field, value)
}

In the example the sendText function, shown below, uses sendEvent to send
an event to the ChangeString node in the VRML, and will change the
field set_string for that node using value.

function sendText(value)
{
sendEvent(‘ChangeString’, ‘set_string’, value);
}
3. Calling JavaScript from VRML:
Here when the touchTime event occurs, set_string is called in the
script node.    The Script method OnEvent() will be called with the specified parameters.
Of course par1 and par2 can be replaced at runtime by actual parameters.

    DEF RotationScript Script {
        field MFString newurl [ “OnEvent( par1, par2 )” ]
        field MFString param [ “” “” ]
        eventIn    SFTime       clicked
        eventIn    SFTime     set_string
        eventOut SFRotation rotation_changed
        url “vrmlscript:
            function clicked (value, time) {
              angle = Math.random()*6.283;
              rotation_changed = new SFRotation(0,1,0,angle);
            }
            function set_string (value, time) {
              Browser.loadURL(newurl,param);
            }
        “
    }

ROUTE RotSensor.touchTime TO RotationScript.set_string
and the HTML definition:
<SCRIPT language=Javascript>
function OnEvent(par1, par2, time)
{ document.sform.sfield.value = par1 + par2 + time; }
</SCRIPT>
4. Use VBScript to activate the OnEvent method with Internet Explorer:
Internet Explorer doesn’t allow to call Javascript directly from a C program. Therefore VBScript has to be used to pass the call to Javascript. The name of the sub is <objectid>_OnEvent.

<scriptlanguage=
VBScript>
<!–    sub CC3D_OnEvent(par1, par2, time)
OnEvent par1, par2, time
end sub
!–>
</script>
Examples

Please check the blaxxun Client SDK.

发布于 :未分类

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注